

from view.endSrc.tHighDensityFilter import tHighDensityFilter

class ModeFilter:

    def __init__(self, filterTable: tHighDensityFilter):

        assert filterTable.id, 'A valid DB id must be given'

        self.filterTable = filterTable
        self.logger = filterTable.getLogger()

    def __call__(self, ids: list):
        # https://docs.python.org/3/library/exceptions.html#exception-hierarchy
        assert False, 'The __call__ method must be implemented by subclasses of ModeFilter'

    def writeOutputIdsToDB(self, outputIds: list, filterClassName, filterParamsJSONDict):

        if not self.filterTable.updateOutputIds(outputIds, filterClassName, filterParamsJSONDict):
            tmp = 'ModeFilter(' + str(filterClassName) + ').writeOutputIdsToDB..failed to write ids:'
            tmp += str(outputIds) + '\n'
            tmp += ', params: ' + str(filterParamsJSONDict)

            self.logger.write(tmp)
